/*
 * @Author: Zhouhai 497675647@qq.com
 * @Date: 2022-12-01 14:14:55
 * @LastEditors: Zhouhai 497675647@qq.com
 * @LastEditTime: 2022-12-01 15:06:35
 */
/* eslint-disable @typescript-eslint/no-unused-vars */
import { updateUserPwd } from '@/api/system/user';
import { useStore } from '@/store';
import { Button, Form, FormInstance, Input, message } from 'antd';
import React, { useRef } from 'react'
import './index.less';
const ResetPwd: React.FC = () => {
    const [form] = Form.useForm();
    const { layoutStore } = useStore()
    const submit = (data: any) => {
        layoutStore.OpenSpanning()
        updateUserPwd(data.oldPassword, data.newPassword).then(()=>{
            form.resetFields()
            message.success('修改成功！')
        }).finally(() => layoutStore.CloseSpanning())

    }
    return (
        <Form
            onFinish={submit}
            form={form}
            name="basic"
            autoComplete="off"
            labelCol={{ span: 2 }}
            wrapperCol={{ span: 21 }}>
            <Form.Item
                label="旧密码"
                name="oldPassword"
                rules={[{ required: true, min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间' }]}
            >
                <Input.Password />
            </Form.Item>
            <Form.Item
                label="新密码"
                name="newPassword"
                rules={[{ required: true, min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间' }]}
            >
                <Input.Password />
            </Form.Item>
            <Form.Item
                label="确认密码"
                name="confirmPassword"
                rules={[
                    { required: true, min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间' },
                    ({ getFieldValue }) => ({
                        validator(_, value) {
                            if (!value || getFieldValue('newPassword') === value) {
                                return Promise.resolve();
                            }
                            return Promise.reject(new Error('新密码与确认密码必须一致!'));
                        },
                    }),
                ]}
            >
                <Input.Password />
            </Form.Item>
            <Form.Item
                wrapperCol={{ span: 14, offset: 1 }}
            >
                <Button type="primary" htmlType="submit">提交</Button>
            </Form.Item>
        </Form >
    )
}
export default ResetPwd;